$('.right-titleicon').on("click",function(e){
	projectVM.showMenulist()
})
//厂长审批的钥匙类型
var keyTypeStation=['4','5','6']//生产经理审批的钥匙类行
var keyTypeManage=['6']//厂长审批的钥匙类型
projectVM = new Vue({
	el: "#content", 
	components:{ 
		personselect,
		processlog
	},
	data: {
		param:'',
		workId:'',
		keyOperate:[],
		isSingle:false,
		keyList:[],
		menuList:[
			{name:'借用',path:'borrow.html'},{name:'归还',path:'return.html'},
			{name:'列表',path:'index.html'},{name:'我值班'},
		],
		onStatus:'',
		result:'',
		showMenu:false,
		showMorebtn:false,
		advance:'',
		detail:'',
		workStatus:'',
		showAdd:false,
		showAble:false,
		show_popup:false,
		showSubmit:false,
		desc:'',
		neiosGoDetailData:"",
	},
	created: function() {
		console.log("=====neiosGoDetail======",JSON.stringify(localStorage.getItem("neiosGoDetail")))
		let keydata = localStorage.getItem("neiosGoDetail")
		if(null != keydata && "" != keydata){
			this.neiosGoDetailData = JSON.parse(localStorage.getItem("neiosGoDetail"))
			if(this.neiosGoDetailData.alwinType == 0){
				this.getSearchDetail()
				localStorage.setItem('neiosGoDetail',"")
				return;
			}
			//localStorage.setItem('neiosGoDetail',"")
		}

		this.userInfo = JSON.parse(localStorage.getItem("neiosUser"))
		console.log("localStorage.getItem('keyOperate')",JSON.stringify(localStorage.getItem('keyOperate')))
		if(localStorage.getItem('keyOperate')){
				this.detail =JSON.parse(localStorage.getItem('keyOperate'))
				this.getDetail()
				localStorage.removeItem('keyOperate')
				this.workId = this.detail.workId
		}
		else{
			this.workStatus = JSON.parse(localStorage.getItem('todoWork')).obj.workStatus
			this.workId = JSON.parse(localStorage.getItem('todoWork')).obj.workId
			console.log("______:"+JSON.parse(localStorage.getItem('todoWork')))
			this.getInfo()
			this.showAble = true
		}
	},
	mounted(){
		if(this.detail != ''){
				this.$refs.personselect1.person = '[' + this.detail.operateStaffCode + ']' + this.detail.operateStaffName
				this.$refs.personselect2.person = '[' + this.detail.dutyStaffCode + ']' + this.detail.dutyStaffName
		}
	},
	methods: {
		//综合查询详情
		getSearchDetail(){
			var that = this
			console.log("=======",JSON.stringify(this.neiosGoDetailData.obj.outWorkId))
			that.workId = this.neiosGoDetailData.obj.outWorkId
			var param = {
				workId:this.neiosGoDetailData.obj.outWorkId
			}
			mui.neiosRequst.httpRequst('/app/currentEntry/keyOperate/getBorrowKeysByWorkId', param,
			function(data) {
				console.log("回调："+JSON.stringify(data))
				if(data.code == 0){
					console.log(JSON.stringify(data))
					that.keyOperate = data.data.neiosKeyOperate
					that.keyList = data.data.keyOperateInfoVos
					if(data.data.keyOperateInfoVos.length == 0){
						that.getKeylist(data.data.neiosKeyOperate.keyOperateId)
					}
					that.$refs.personselect1.person = '[' + that.keyOperate.operateStaffCode + ']' + that.keyOperate.operateStaffName
					that.$refs.personselect2.person = '[' + that.keyOperate.dutyStaffCode + ']' + that.keyOperate.dutyStaffName
				}
			},
			function(data){
			
			});
		},
		//获取钥匙列表
		getKeylist(e){
			var that = this
			var param = {
				keyOperateId:e
			}
			mui.neiosRequst.httpRequst('/app/currentEntry/keyOperate/getReturnKeyInfoList', param,
			function(data) {
				that.keyList = data.data
			},
			function(data){
				
			}
			)
		},
		//通过workid 获取信息
		getInfo(){
			var that = this
			var param = {
				workId:this.workId
			}
			mui.neiosRequst.httpRequst('/app/currentEntry/keyOperate/getBorrowKeysByWorkId', param,
			function(data) {
				if(data.code == 0){
					console.log(JSON.stringify(data))
					that.keyOperate = data.data.neiosKeyOperate
					that.keyList = data.data.keyOperateInfoVos
					if(data.data.keyOperateInfoVos.length == 0){
						that.getKeylist(data.data.neiosKeyOperate.keyOperateId)
					}
					that.$refs.personselect1.person = '[' + that.keyOperate.operateStaffCode + ']' + that.keyOperate.operateStaffName
					that.$refs.personselect2.person = '[' + that.keyOperate.dutyStaffCode + ']' + that.keyOperate.dutyStaffName
				}
			},
			function(data){

			});
		},
		submitAdd(){
			var param = this.param
			if(this.$refs.personselectNext.person == ''){
				mui.toast('请选择审批人')
				return
			}		
			param.nodeDealStaffCode= this.$refs.personselectNext.personids,
			param.nodeDealStaffName=this.$refs.personselectNext.person.split(']')[1] 
			console.log(JSON.stringify(param))
			
			mui.neiosRequst.httpRequst('/app/currentEntry/keyOperate/saveOrUpdateKeyOperate', param,
			function(data) {
				if(data.code == 0){
					mui.toast('操作成功')
					setTimeout(() => {
						let page = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
						let pageId = plus.webview.getWebviewById(page.id); 
						let param = {} 
						param.isRefresh = true
						mui.fire(pageId, 'isRefresh', param);
						mui.back()
					}, 1000);
				}
			},
			function(data){
		
			}
			);
		},
		//通过
		goOn(){
			var arr = this.keyList
			var that = this
			var keyManage = []
			arr.forEach(item=>{
				keyManage.push({
					keyManageId:item.keyManageId,
					status:0
				})
			})
			var stationKeyList = []
			var manageKeyList = []
			
            this.keyList.map((v, i) => {
                if (keyTypeStation.indexOf(v.keyType) != '-1') {
                    stationKeyList.push(v)
                }
                if (keyTypeManage.indexOf(v.keyType) != '-1') {
                   manageKeyList.push(v)
                }
            })
			var param = {
				currentUser: this.userInfo,
				desc:this.desc,
				isBack: false,
				isDone: true,
				isShowManage: false,
				isShowStation: false,
				isSubmit: true,
				keyManage:keyManage,
				keyOperate:this.keyOperate,
				keyOperateInfo:this.keyList,
				manageKeyList:manageKeyList,
				nodeDealStaffCode: this.keyOperate.operateStaffCode,
				nodeDealStaffName:this.keyOperate.operateStaffName,
				saveType: "U",
				stationKeyList:stationKeyList,
				workId:this.wordId,
				workType: "0202"
			}
			  if (this.workStatus == '15') {
			//不需要场长审批
			  if (!stationKeyList.length > 0) {
			         param.isSubmit = true;
			        param.isShowStation = false;
			        param.isShowManage = false;
			        param.isDone = true;
			        that.param = param;
					//不需要生产经理审批
					if (!manageKeyList.length > 0) {
					    param.isShowStation = false;
					    param.isShowManage = false;
					   param.isSubmit = true;
					    param.isDone = true;
					} else {
					    //需要生产经理审批
					    param.isShowStation = false;
					    param.isShowManage = true;
					    param.isSubmit = true;
					    param.isDone = false;
						that.param = param;
						that.showSubmit = true;
						return
					}
					
					} else {
						//需要场长审批
			             param.isSubmit = true;
			            param.isShowStation = true;
			            param.isShowManage = false;
			            param.isDone = false;
			              that.param = param;
						that.showSubmit = true;
						return
			        }
					
					
			    }
							if (this.workStatus == '20') {
                                        //不需要生产经理审批
                                        if (!manageKeyList.length > 0) {
                                            param.isShowStation = false;
                                            param.isShowManage = false;
                                           param.isSubmit = true;
                                            param.isShowStation = false;
                                            param.isShowManage = false;
                                            param.isDone = true;
                                        } else {
                                            //需要生产经理审批
                                            param.isShowStation = false;
                                            param.isShowManage = true;
                                            param.isSubmit = true;
                                            param.isShowStation = false;
                                            param.isShowManage = true;
                                            param.isDone = false;
											that.param = param;
											that.showSubmit = true;
											return
                                        }
                                    }
                        if (this.workStatus == '30') {
                                        param.isShowStation = false;
                                       param.isShowManage = false;
                                        param.isSubmit = true;
                                        param.isShowStation = false;
                                        param.isDone = true;
                                }
				if(param.isDone == true){
					param.keyManage.forEach(item=>{
						item.status = 1
					})
				}
			mui.neiosRequst.httpRequst('/app/currentEntry/keyOperate/saveOrUpdateKeyOperate', param,
				function(data) {
					mui.toast('操作成功')
					setTimeout(()=>{
						let page = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
						let pageId = plus.webview.getWebviewById(page.id); 
						let param = {} 
						param.isRefresh = true
						mui.fire(pageId, 'isRefresh', param);
						mui.back()
					},1000)
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//退回
		sendBack(){
		
			if(this.desc == ''){
				mui.toast('请输入审批意见')
				return
			}
			var url = '/app/currentEntry/keyOperate/sendBackKeyOperate'
			var that = this
			let param = {
				approveDesc: this.desc,
				forwardNode: "1",
				nodeDealStaffCode: this.keyOperate.createStaffName,
				nodeDealStaffName: this.keyOperate.createBy,
				nodeDealStaffRole: "0",
				nodeVisibleRange: "20",
				workId: this.keyOperate.workId,
				workType: "0202",
			}
			mui.neiosRequst.httpRequst(url, param,
				function(data) {
					if(data.code == 0){
						console.log(JSON.stringify(data))
						mui.toast('操作成功')
						setTimeout(() => {
							let page = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
							let pageId = plus.webview.getWebviewById(page.id); 
							let param = {} 
							param.isRefresh = true
							mui.fire(pageId, 'isRefresh', param);
							mui.back()
						}, 1000);
					}
					
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		getDetail(){
			var url = '/app/currentEntry/keyOperate/getBorrowKeyInfoList'
			var that = this
			let param = {
				keyOperateId:this.detail.keyOperateId
			}
			console.log("====getDetail执行了====",this.detail)
			mui.neiosRequst.httpRequst(url, param,
				function(data) {
					that.keyList = data.data
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//返回上一页
		goBack(){
			mui.back()
		},
		//更多按钮
		showMore(){
			this.showMorebtn ? this.showMorebtn = false : this.showMorebtn = true
		},
		//阻止事件冒泡
		clickStop(){

		},
		//选择是否为值班人
		checkOnstatus(){
			console.log(this.onStatus)
			this.onStatus ? this.onStatus = false : this.onStatus =true
			
		},
		//点击菜单
		menuClick(e){
			if(e.name == '我值班'){
				this.onStatus? this.onStatus= false : this.onStatus=true
			}else{
				this.showMenu = false
				this.navTo(e.path)
			}
		},
		//左上角菜单显示隐藏
		showMenulist(){
			this.showMenu?this.showMenu=false:this.showMenu=true
		},
		navTo(e){
			mui.openWindow({
					url: e,
					id: e,
			});
			}
	},
	
	})